const index = require("@_controller/index"); 
const fastify = require("../app");

const apiRoutes = [
  {
    url: "/index",
    method: "GET",
    handler: index.index
  },
  {
    url: "/index",
    children: [
      {
        url: "/index",
        method: "GET",
        handler: index.index
      },
    ]
  }
]
const wsRoutes = [
  // {
  //   url: "",
  //   websocket: true,
  //   handler: handler
  // },

]

function registerRoutes(fastify,routes, prefix = "") {
  routes.forEach((route) => {
    if (route.children) {
      const path = prefix + route.url;
      registerRoutes(fastify,route.children, path);
    } else {
      const rou =  {
        ...route,
        url: prefix + route.url
      };
      fastify.route(rou);
    }
  });
}
async function routes(fastify, options) {
  // apiRoutes.forEach((route) => {
  //   fastify.route(route);
  // })
  registerRoutes(fastify,apiRoutes);
  // fastify.post('/example', { schema: postSchema }, async (request, reply) => {
  //     const { name, age } = request.body;
  //     const id = Math.random().toString(36).substring(7); // Generate a random ID
  //     return { id, name, age };
  // });
}


module.exports = {
  routes,
  wsRoutes
}
